package com.cwz.api.factory;

import com.cwz.api.entity.SysUser;
import com.cwz.api.model.LoginUser;
import com.cwz.api.remote.RemoteUserService;
import com.cwz.core.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @program: w-demo
 * @description: 用户服务降级处理
 * @author: Wen
 **/
@Component
@Slf4j
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService> {
	@Override
	public RemoteUserService create(Throwable cause) {
		log.error("用户服务调用失败:{}", cause.getMessage());
		return new RemoteUserService() {
			@Override
			public R<LoginUser> getUserInfo(String username, String source) {
				return R.fail("获取用户失败:" + cause.getMessage());
			}

			@Override
			public R<Boolean> registerUserInfo(SysUser sysUser, String source) {
				return R.fail("注册用户失败:" + cause.getMessage());
			}
		};
	}
}
